package com.yvan.leto.server.config;

import com.yvan.leto.ConfigRegistry;
import com.yvan.leto.server.dao.ProjectPersistent;
import com.yvan.leto.server.dao.RepositoryPersistent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(LetoServerProperties.class)
public class LetoAutoConfiguration {

    private final LetoServerProperties letoServerProperties;

    @Autowired
    public LetoAutoConfiguration(LetoServerProperties letoServerProperties) {
        this.letoServerProperties = letoServerProperties;
    }

    @Bean
    ConfigRegistry letoRegistry() {
        ConfigRegistry configRegistry = new ConfigRegistry();
        configRegistry.init(letoServerProperties);
        return configRegistry;
    }

    @Bean
    public RepositoryPersistent repositoryPersistent() {
        return new RepositoryPersistent(letoServerProperties.getRepository());
    }

    @Bean
    public ProjectPersistent projectPersistent() {
        return new ProjectPersistent(letoServerProperties.getRepository());
    }

}
